package xin.clips.common.utils;

/**
 * 生成随机数
 */
public class ProducerNumUtil {
    private static final Integer ONE = 1;
    private static final Integer TWO = 2;
    private static final Integer THREE = 3;

    // prefix为自定义前缀，想要几位数可以自行修改0的数量
    // id获取方式为从数据库表中查询现在最大id+1（SELECT id+1  from table  ORDER BY id DESC LIMIT 1）
    public static String getId(String prefix, Integer id){
        //判断位数
        String s = id + "";
        int count = s.length();
        String producerNum = prefix;
        if (ONE == count){
            producerNum += "000"+ String.valueOf(id);
        }else if (TWO == count){
            producerNum += "00"+ String.valueOf(id);
        }else if (THREE == count){
            producerNum += "0" + String.valueOf(id);
        }else {
            producerNum += String.valueOf(id);
        }
        return producerNum;
    }
}
